package ch.zbw.pra.sysventory.ui.gui.panels.overviewandsearchpanel.subpanels.detailPanel;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import ch.zbw.pra.sysventory.domain.model.Computer;
import ch.zbw.pra.sysventory.ui.gui.panels.overviewandsearchpanel.subpanels.detailPanel.DetailTablePanel.DetailTableEnum;
import ch.zbw.pra.sysventory.ui.gui.utilities.DefaultFonts.FontType;
import ch.zbw.pra.sysventory.ui.gui.utilities.GuiLayout;
import ch.zbw.pra.sysventory.ui.gui.utilities.TextLayout;

public class LeftDetailPanel extends JPanel {
	private static final long serialVersionUID = -425796235420276183L;
	// Computer
	private JLabel hostname;
	private JTextField hostnameField;
	private JLabel sid;
	private JTextField sidField;
	private JLabel computerTyp;
	private JTextField computerTypField;
	private JLabel ram;
	private JTextField ramField;
	// OS
	private JLabel osName;
	private JTextField osNameField;
	private JLabel architektur;
	private JTextField architekturField;
	private JLabel buildNr;
	private JTextField buildNrField;
	private JLabel prozessorName;
	private JTextField prozessorNameField;
	private JLabel prozFamily;
	private JTextField prozFamilyField;
	private JLabel anzKerne;
	private JTextField anzKerneField;
	private JLabel clock;
	private JTextField clockField;

	private Computer computer;

	public LeftDetailPanel(Computer computer) {
		this.computer = computer;

		this.hostname = new JLabel("Hostname");
		this.hostnameField = new JTextField();
		this.sid = new JLabel("SID");
		this.sidField = new JTextField();
		this.computerTyp = new JLabel("Computer-Typ");
		this.computerTypField = new JTextField();
		this.ram = new JLabel("RAM in MB");
		this.ramField = new JTextField();
		this.osName = new JLabel("Betriebsystem");
		this.osNameField = new JTextField();
		this.architektur = new JLabel("Architektur");
		this.architekturField = new JTextField();
		this.buildNr = new JLabel("Build-Nummer");
		this.buildNrField = new JTextField();
		this.prozessorName = new JLabel("Prozessor-Name");
		this.prozessorNameField = new JTextField();
		this.prozFamily = new JLabel("Prozessor-Familie");
		this.prozFamilyField = new JTextField();
		this.anzKerne = new JLabel("Anzahl Kerne");
		this.anzKerneField = new JTextField();
		this.clock = new JLabel("Taktrate in MHz");
		this.clockField = new JTextField();

		// fill the Datas in Fields
		init();
		fillTextfieldsWithComputerDetailDatas();
	}

	public void fillTextfieldsWithComputerDetailDatas() {
		this.hostnameField.setText(this.computer.getHostNameComputer());
		this.sidField.setText(this.computer.getSidComputer());
		this.computerTypField.setText(this.computer.getTypeComputer());
		this.ramField.setText(this.computer.getRamComputer());

		this.osNameField.setText(this.computer.getOs().getNameOperatingSystem());
		this.architekturField.setText(this.computer.getOs()
				.getArchitecture32Bit64BitOperatingSystem());
		this.buildNrField.setText(this.computer.getOs().getBuildOperatingSystem());

		this.prozessorNameField.setText(this.computer.getProcessor().getNameProcessor());
		this.prozFamilyField.setText(this.computer.getProcessor().getFamilyProcessor());
		this.anzKerneField.setText("" + this.computer.getProcessor().getCoresProcessor());
		this.clockField.setText("" + this.computer.getProcessor().getClockProcessor());

	}

	public void init() {

		TextLayout.addStyleToComponent(this.hostname, FontType.SMALL);
		TextLayout.addStyleToComponent(this.sid, FontType.SMALL);
		TextLayout.addStyleToComponent(this.computerTyp, FontType.SMALL);
		TextLayout.addStyleToComponent(this.ram, FontType.SMALL);

		TextLayout.addStyleToComponent(this.osName, FontType.SMALL);
		TextLayout.addStyleToComponent(this.architektur, FontType.SMALL);
		TextLayout.addStyleToComponent(this.buildNr, FontType.SMALL);

		TextLayout.addStyleToComponent(this.prozessorName, FontType.SMALL);
		TextLayout.addStyleToComponent(this.prozFamily, FontType.SMALL);
		TextLayout.addStyleToComponent(this.anzKerne, FontType.SMALL);
		TextLayout.addStyleToComponent(this.clock, FontType.SMALL);

		TextLayout.addStyleToTextComponentAndNotEditable(this.hostnameField, FontType.SMALL, false);
		TextLayout.addStyleToTextComponentAndNotEditable(this.sidField, FontType.SMALL, false);
		TextLayout.addStyleToTextComponentAndNotEditable(this.computerTypField, FontType.SMALL,
				false);
		TextLayout.addStyleToTextComponentAndNotEditable(this.ramField, FontType.SMALL, false);

		TextLayout.addStyleToTextComponentAndNotEditable(this.osNameField, FontType.SMALL, false);
		TextLayout.addStyleToTextComponentAndNotEditable(this.architekturField, FontType.SMALL,
				false);
		TextLayout.addStyleToTextComponentAndNotEditable(this.buildNrField, FontType.SMALL, false);

		TextLayout.addStyleToTextComponentAndNotEditable(this.prozessorNameField, FontType.SMALL,
				false);
		TextLayout.addStyleToTextComponentAndNotEditable(this.prozFamilyField, FontType.SMALL,
				false);
		TextLayout.addStyleToTextComponentAndNotEditable(this.anzKerneField, FontType.SMALL, false);
		TextLayout.addStyleToTextComponentAndNotEditable(this.clockField, FontType.SMALL, false);

		int x = 0;
		int y = 0;
		GridBagLayout gridBagLayout = GuiLayout.getGridBagLayout(this);

		double label = 0.0;
		double textField = 1.0;

		GridBagConstraints gridBagConstraints = GuiLayout.getGridBagConstraints();
		gridBagLayout = GuiLayout.getGridBagLayout(this);
		gridBagLayout.columnWeights = new double[] { label, textField };
		gridBagLayout.columnWidths = new int[] { 150, 150 };
		Insets forAll = new Insets(1, 5, 0, 5);
		Insets forTitle = new Insets(10, forAll.left, forAll.bottom, forAll.right);
		gridBagConstraints.insets = forAll;
		y++;
		x = 0;
		JLabel introText = new JLabel("Detailansicht f\u00FCr Host: "
				+ this.computer.getHostNameComputer());
		TextLayout.addStyleToComponent(introText, FontType.BIG);
		gridBagConstraints.insets = forTitle;
		GuiLayout.addToLayout(this, gridBagLayout, gridBagConstraints, x++, y, 2, 1, introText);
		// don't needed because whitespace: gridBagConstraints.insets = forAll;
		y++;
		x = 0;
		// Empty whitespace

		GuiLayout.addToLayout(this, gridBagLayout, gridBagConstraints, x++, y, 2, 1, new JLabel());
		gridBagConstraints.insets = forAll;
		y++;
		x = 0;
		// computer
		JLabel computerDetail = new JLabel("Computer-Details:");
		TextLayout.addStyleToComponent(computerDetail, FontType.MEDIUM);
		GuiLayout
				.addToLayout(this, gridBagLayout, gridBagConstraints, x++, y, 1, 1, computerDetail);
		y++;
		x = 0;
		GuiLayout.addNextRowToLayout(this, gridBagLayout, gridBagConstraints, x++, y,
				this.hostname, this.hostnameField);
		y++;
		x = 0;
		GuiLayout.addNextRowToLayout(this, gridBagLayout, gridBagConstraints, x++, y, this.sid,
				this.sidField);
		y++;
		x = 0;
		GuiLayout.addNextRowToLayout(this, gridBagLayout, gridBagConstraints, x++, y,
				this.computerTyp, this.computerTypField);
		y++;
		x = 0;
		GuiLayout.addNextRowToLayout(this, gridBagLayout, gridBagConstraints, x++, y, this.ram,
				this.ramField);
		y++;
		x = 0;
		// OS
		JLabel osDetail = new JLabel("Betriebsystem-Details");
		TextLayout.addStyleToComponent(osDetail, FontType.MEDIUM);
		gridBagConstraints.insets = forTitle;
		GuiLayout.addToLayout(this, gridBagLayout, gridBagConstraints, x++, y, osDetail);
		gridBagConstraints.insets = forAll;
		y++;
		x = 0;
		GuiLayout.addNextRowToLayout(this, gridBagLayout, gridBagConstraints, x++, y, this.osName,
				this.osNameField);
		y++;
		x = 0;
		GuiLayout.addNextRowToLayout(this, gridBagLayout, gridBagConstraints, x++, y, this.buildNr,
				this.buildNrField);
		y++;
		x = 0;
		GuiLayout.addNextRowToLayout(this, gridBagLayout, gridBagConstraints, x++, y,
				this.architektur, this.architekturField);
		y++;
		x = 0;

		// Processors
		JLabel prozDetail = new JLabel("Prozessor-Details:");
		TextLayout.addStyleToComponent(prozDetail, FontType.MEDIUM);
		gridBagConstraints.insets = forTitle;
		GuiLayout.addToLayout(this, gridBagLayout, gridBagConstraints, x++, y, 1, 1, prozDetail);
		gridBagConstraints.insets = forAll;
		y++;
		x = 0;
		GuiLayout.addNextRowToLayout(this, gridBagLayout, gridBagConstraints, x++, y,
				this.prozessorName, this.prozessorNameField);
		y++;
		x = 0;
		GuiLayout.addNextRowToLayout(this, gridBagLayout, gridBagConstraints, x++, y,
				this.prozFamily, this.prozFamilyField);
		y++;
		x = 0;
		GuiLayout.addNextRowToLayout(this, gridBagLayout, gridBagConstraints, x++, y,
				this.anzKerne, this.anzKerneField);
		y++;
		x = 0;
		GuiLayout.addNextRowToLayout(this, gridBagLayout, gridBagConstraints, x++, y, this.clock,
				this.clockField);
		y++;
		x = 0;
		gridBagConstraints.insets = forTitle;
		GuiLayout.addToLayout(this, gridBagLayout, gridBagConstraints, x++, y, 2, 1, new JLabel(
				"Drucker-\u00DCbersicht"));
		gridBagConstraints.insets = forAll;
		y++;
		x = 0;
		// Printers
		GuiLayout.addToLayout(this, gridBagLayout, gridBagConstraints, x++, y, 2, 1, 1, 1,
				new DetailTablePanel(this.computer, DetailTableEnum.PRINTER));
		y++;
		x = 0;

		this.setVisible(true);
	}

}
